package cn.wangliang181230.boot.configcenter.restcontroller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MyConfigController {

	private static final Map<String, Map<String, String>> configMap;

	static {
		configMap = new HashMap<>();

		// application-dev
		{
			Map<String, String> properties = new HashMap<>();
			properties.put("my.test.string", "dev");

			configMap.put("application-dev", properties);
		}
		// test-properties
		{
			Map<String, String> properties = new HashMap<>();
			properties.put("my.test.string", "test");

			configMap.put("application-test", properties);
		}
		// prod-properties
		{
			Map<String, String> properties = new HashMap<>();
			properties.put("my.test.string", "prod");

			configMap.put("application-prod", properties);
		}
	}


	@GetMapping("/getConfig")
	public Map<String, String> getConfig(@RequestParam String dataId) {
		return configMap.get(dataId);
	}

}
